﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

namespace tools{
public class XMlCoder {

	private XmlDocument doc; 
	private Dictionary<string,Dictionary<string,string>> dic = new Dictionary<string,Dictionary<string,string>>();

	public XMlCoder(){
		return;
		string path = "";
		if (Application.platform == RuntimePlatform.Android) 
		{
			path = Application.persistentDataPath;
		}
		else if(Application.platform==RuntimePlatform.WindowsPlayer)
		{
			path=Application.dataPath;
		}
		else if(Application.platform==RuntimePlatform.WindowsEditor)
		{
			path=Application.dataPath;
		}

		doc = new XmlDocument ();
		doc.Load (path+"/Resources/CashData/CoderXml.xml");

		XmlNodeList nodeList = doc.SelectSingleNode("coders").ChildNodes;

		foreach (XmlNode xn in nodeList) {//遍历所有子节点 

			XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 

			Dictionary<string,string> dic2 = new Dictionary<string,string>();
			dic[xe.GetAttribute ("head").ToString()] = dic2;
			Debug.Log(xe.GetAttribute ("head").ToString());
			XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点 

			foreach (XmlNode xn1 in nls) {//遍历 

				XmlElement xe2 = (XmlElement)xn1;//转换类型

				dic2[xe2.GetAttribute("name").ToString()] = xe2.GetAttribute("length").ToString();
			
			} 
		}
	}

	public Dictionary<string,string> getDic(string value){
		return dic[value];
	}
}
}